package ca.compsci.opent.doctool;

/**
 * Models a procedure/function parameter. It is similar to a var, except it
 * a param can have 'var' modifier on it.
 * 
 * @since 0.0.2
 */
public class Param extends Var
{
	/**
	 * Signifies if this parameter has the OpenT 'var' modifier
	 * 
	 * @since 0.0.2
	 */
	private boolean isVar;
	
	/**
     * Models a OpenT proc/fcn parameter.
     *
     * @param identifier the parameter identifier in code
	 * @param type type that this parameter is in OpenT code
	 * @param isVar denotes if this parameter has the 'var' modifier
	 * 
	 * @since 0.0.2
     */
    public Param(String identifier, Type type, boolean isVar)
    {
		super(identifier, type);
		
		this.isVar = isVar;
    }
	
	/**
	 * Returns if this parameter has the {@code var} modifier in OpenT code.
	 * 
	 * @return {@code true} if value has {@code var} modifier, {@code false}
	 *	otherwise
	 *
	 * @since 0.0.2
	 */
	public boolean isVar()
	{
		return isVar;
	}
	
	/**
	 * Returns the string representation of this {@code Param}.
	 * 
	 * <p>
	 * A parameter's string representation is its identifier and its type,
	 * preceeded by "var" if {@link #isVar} returns {@code true}:
	 * {@code [var] <i>identifier</i> : <i>type</i>}.
	 * </p>
	 * 
	 * @return string representation of parameter
	 * 
	 * @since 0.0.2
	 */
	@Override
	public String toString()
	{
		return isVar 
			? super.toString() 
			: super.toString().replace("var ", "");
	}

}
